<template>
	<view>
		<!-- <u-sticky>
			<view class="search">
				<u-search shape="round" :showAction="false"></u-search>
			</view>
		</u-sticky> -->
		<view class="" v-if="type == 1">
			<view class="list_box" v-if="mydata !== undefined && mydata!== null && mydata.length>0">
				<view class="list" v-for="(item,index) in mydata" :key="index" @click="order(index)">
					<text>{{item.name}}</text>
					<text>{{item.phone}}</text>
				</view>
			</view>
			<u-empty v-else mode="list" icon="/static/Empty/data_null.png">
			</u-empty>
		</view>
		<view class="" v-if="type == 2">
			<view class="list_box" v-if="policy !== undefined && policy!== null && policy.length>0">
				<view class="list" v-for="(item,index) in policy" :key="index" @click="order(index)">
					<text>{{item.title}}</text>
				</view>
			</view>
			<u-empty v-else mode="list" icon="/static/Empty/data_null.png">
			</u-empty>
		</view>
		<view class="" v-if="type == 3">
			<view class="list_box" v-if="ProductList !== undefined && ProductList!== null && ProductList.length>0">
				<view class="list" v-for="(item,index) in ProductList" :key="index" @click="order(index)">
					<text>{{item.name}}</text>
				</view>
			</view>
			<u-empty v-else mode="list" icon="/static/Empty/data_null.png">
			</u-empty>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				mydata: [],
				policy: [],
				ProductList:[],
				type: null,
				page:1,
				bottom:true
			}
		},
		onLoad(e) {
			this.type = e.type
			if (this.type == 1) {
				this._list()
			} else if(this.type == 2){
				this._policy()
			}else{
				this._ProductList()
			}
		},
		//下拉刷新
		onReachBottom() {
			// if (this.bottom == true) {
			// 	this.page += 1
			// 	this._policy()
			// }
		},
		methods: {
			// 人员列表
			async _list() {
				uni.showLoading({
					title: '加载中'
				});
				const userinfo = uni.getStorageSync('userinfo');
				const {
					data: res
				} = await this.$myHttp5({
					url: 'setting/getChild',
					data: {},
					header: {
						'token': userinfo.token
					},
				});
				uni.hideLoading()
				this.mydata = res.data
			},
			// 政策列表
			async _policy() {
				uni.showLoading({
					title: '加载中'
				});
				const userinfo = uni.getStorageSync('userinfo');
				const {
					data: res
				} = await this.$myHttp5({
					url: 'setting/getPolicyList',
					data: {
						page:this.page,
						page_size:15
					},
					header: {
						'token': userinfo.token
					},
				});
				if (res.code == 1) {
					if (res.data.data !== undefined && res.data.data !== null && res.data.data.length >
						0) {
						if (this.page == 1) {
							this.policy = res.data.data
							uni.hideLoading()
						} else {
							this.policy = [...this.policy, ...res.data.data]
							uni.hideLoading()
						}
					} else {
						uni.hideLoading()
						this.bottom = false
					}
				} else {
					uni.showToast({
						title: res.msg,
						duration: 1000,
						icon: "none"
					});
					this.bottom = false
				}
			},
			// 政策列表
			async _ProductList() {
				uni.showLoading({
					title: '加载中'
				});
				const userinfo = uni.getStorageSync('userinfo');
				const {
					data: res
				} = await this.$myHttp5({
					url: 'setting/getEquipProductList',
					data: {},
					header: {
						'token': userinfo.token
					},
				});
				if (res.code == 1) {
					this.ProductList = res.data
					uni.hideLoading()
				} else {
					uni.showToast({
						title: res.msg,
						duration: 1000,
						icon: "none"
					});
					this.bottom = false
				}
			},
			order(index) {
				if (this.type == 1) {
					uni.$emit('updateData', this.mydata[index])
					uni.navigateBack({
						delta: 1
					})
				}else if(this.type == 2){
					uni.$emit('updatepolicy', this.policy[index])
					uni.navigateBack({
						delta: 1
					})
				}else{
					uni.$emit('updateProduct', this.ProductList[index])
					uni.navigateBack({
						delta: 1
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.search {
		padding: 30rpx;
		box-sizing: border-box;
		background-color: #fff;
	}

	.list_box {
		padding: 30rpx;
		box-sizing: border-box;

		.list {
			display: flex;
			flex-direction: column;
			padding: 0 30rpx 30rpx 30rpx;
			box-sizing: border-box;
			border-bottom: 1px solid #eeeeee;

			text {
				padding-top: 20rpx;
				font-size: 28rpx;
			}
		}
	}
</style>
